﻿@using Newtouch.Common.Operator;
@{
    ViewBag.Title = "BookkeepingQuery";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<form name="form1">
    <div class="panel panel-default">
        <div class="panel-heading navb-bg">
            筛选条件
        </div>
        <div style="padding: 2px;padding-right:20px;">
            <table class="form">
                <tr>
                    <th class="formTitle" id="th_zyh" style="display:none">住院号：</th>
                    <td class="formValue" id="td_zyh" style="display:none">
                        <input type="text" class="form-control" id="zyh" placeholder="" />
                    </td>
                    <th class="formTitle">病历号：</th>
                    <td class="formValue">
                        <input type="text" class="form-control" id="blh" placeholder="" style="width: 54%; float: left;" />
                        <input type="button" class="btn btn-default btn-md btn-default-color" style="margin-left: 2%;" title="选择病人" value="查询" onclick="GetPatSerarchView($('#blh').val(), $('#kehu').val());">
                    </td>
                    <th class="formTitle">客户姓名：</th>
                    <td class="formValue">
                        <input type="text" class="form-control" id="kehu" placeholder="" />
                    </td>
                    <th class="formTitle">售卖人员：</th>
                    <td class="formValue">
                        <input type="text" readonly="readonly" class="form-control" id="smry" data-smryCode="@OperatorProvider.GetCurrent().rygh" data-staffId="@OperatorProvider.GetCurrent().StaffId" value=@OperatorProvider.GetCurrent().UserName />
                    </td>
                    <th class="formTitle">售卖科室：</th>
                    <td class="formValue formDdlSelectorTd" style="width: 11%;">
                        <select id="smks" class="form-control">
                            <option>==请选择==</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">项目分类：</th>
                    <td class="formValue formDdlSelectorTd">
                        <select id="sfdl" class="form-control">
                            <option value="">==请选择==</option>
                        </select>
                    </td>
                    <th class="formTitle">收费项目：</th>
                    <td class="formValue">
                        <input type="text" class="form-control form-an" id="keyword" placeholder="代码 名称" />
                    </td>
                    <th class="formTitle">记账日期：</th>
                    <td class="formValue" colspan="3">
                        <input id="kssj" type="text" class="form-control input-wdatepicker form-an" style="width:42%; float:left;" value="@DateTime.Now.ToString("yyyy-MM-01")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                        <span style="margin-left:1%;float:left;">—</span>
                        <input id="jssj" type="text" class="form-control input-wdatepicker form-an" style="width :42%;float:left;margin-left:1%;" value="@DateTime.Now.ToString("yyyy-MM-dd")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                    </td>
                    <td class="formValue">
                        <input type="button" id="btn_search" class="btn btn-primary form-an" style="width:85%" value="查询" />
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <div class="gridPanel">
        <table class="form" style="width:100%;height:25px;background-color:white;">
            <tr>
                <td>
                    <label style="height:7px;width:17%; margin-left:20%;background-color:white; border:1px solid #ddd"></label>
                    <span>&nbsp;表示未退费</span>
                </td>
                <td>
                    <label style="height:7px;width:17%; background-color:#f2dede; border:1px solid #ddd"></label>
                    <span>&nbsp;表示退费</span>
                </td>
                <td colspan="2"></td>
                <td colspan="2"></td>
                <td></td>
            </tr>
        </table>
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
</form>

<script>
    $(function () {
        initControl();

        gridList();
    });

    //病历号回车
    $('#blh').keydownEnterEvent(function () {
        if (!$("#blh").val().trim()) {
            return;
        }
        var blh = $("#blh").val();
        $('#blh').val(blh.toUpperCase());
        $("#btn_search").trigger('click');
    })
    //住院号开关
    var isShowZyh = '@ViewBag.IsShowZyh';
    if (isShowZyh == 'ON') {
        $('#th_zyh').css('display', 'table-cell');
        $('#td_zyh').css('display', 'table-cell');
        //住院号回车
        $('#zyh').keydownEnterEvent(function () {
            if (!$("#zyh").val().trim()) {
                return;
            }
            var zyh = $("#zyh").val();
            $('#zyh').val(zyh.toUpperCase());
            $("#btn_search").trigger('click');
        })
    }

    //病人查询
    function GetPatSerarchView(blh, xm) {
        if (!!!blh) {
            blh = '';
        };
        if (!!!xm) {
            xm = '';
        };
        $.modalOpen({
            id: "patSearch",
            title: "患者查询",
            url: "/PatientManage/AccountManage/PatOnlyBlhSearchView?t=" + Math.random() + "&blh=" + blh + "&xm=" + xm,
            width: "700px",
            height: "600px",
            callBack: function (iframeId) {
                top.frames[iframeId].PatDbGrid();
            }//窗口点确定的回调函数
        });
    }

    //选择的病人 callback
    function getPatInfoAjax(selePatInfo) {
        $('#blh').val(selePatInfo.blh)
        $('#blh').attr('data-patId', selePatInfo.patId);
        $('#kehu').val(selePatInfo.xm);
    }

    //姓名回车
    $('#kehu').keydownEnterEvent(function () {
        if (!$("#kehu").val().trim()) {
            return;
        }
        $("#btn_search").trigger('click');
    })

    function initControl() {
        //加载收费大类树
        $("#sfdl").bindSelect({
            url: "/NonTreatmentItem/GetTreeSelectChargeCategoryJson"
        });
        $('#smks').bindSelect({
            url: "/SystemManage/SysDepartment/GetTreeSelectJson"
        });
    }

    //默认
    var Editing_ysList = []; //编辑域中的人员
    Editing_ysList = [{ id: $('#smry').attr('data-staffId'), gh: $('#smry').attr('data-smryCode'), Name: $('#smry').val(), ks: $('#smks').attr('data-smksCode'), ksmc: $('#smks').val() }];

    //绑定 人员 树
    $('#smry').click(function () {
        var initIdSelected = "";
        $.each(Editing_ysList, function () {
            initIdSelected += this.id + ",";
        })
        $.modalOpen({
            id: "StaffCorrelation",
            title: "选择售卖人员",
            url: "/SystemManage/SysStaff/Selector?single=true&isContansChildOrg=false&callbackType=json&dutyCode=&initIdSelected=" + initIdSelected,
            showleftlalbel: false,
            width: "650px",
            height: "570px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick(function (data) {
                    staffTreeCallback(data);
                });
            }
        });
    });

    //人员树 选择 回调
    function staffTreeCallback(treeSeleData) {
        Editing_ysList = [];
        $.each(treeSeleData, function () {
            Editing_ysList.push({ id: treeSeleData[0].id, gh: treeSeleData[0].value, Name: treeSeleData[0].text, ks: treeSeleData[0].Ex1, ksmc: treeSeleData[0].Ex2 });
        })
        if (treeSeleData[0]) {
            $('#smry').attr('data-smryCode', treeSeleData[0].value)
                .val(treeSeleData[0].text);
            $('#smks').attr('data-smksCode', treeSeleData[0].Ex1)
                .val(treeSeleData[0].Ex2);

        } else {
            $('#smry').attr('data-smryCode', '')
                .val('');
            $('#smks').attr('data-smksCode', '')
                .val('');

        }
    }

    //明细
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/NonTreatmentItemManage/NonTreatmentItem/SelectNonTreatmentItemList",
            postData: getSearchPostData(),
            height: $(window).height() - 220,
            colModel: [
            { label: '住院号', name: 'zyh', width: 100, align: 'left' },
            { label: '病历号', name: 'blh', width: 100, align: 'left' },
            { label: '客户姓名', name: 'xm', width: 100, align: 'left' },
            { label: "项目类别", name: "dlName", width: 100, align: "left" },
            { label: "项目名称", name: "sfxmName", width: 100, align: "left" },
            { label: "数量", name: "sl", width: 75, align: "left" },
            {
                label: "金额", name: "je", width: 75, align: "left",
                formatter: function (val) {
                    if (val) {
                        return val.toFixed(2);
                    } else {
                        return '';
                    }
                }
            },
            {
                label: "单价", name: "dj", width: 75, align: "left",
                formatter: function (val) {
                    if (val) {
                        return val.toFixed(4);
                    } else {
                        return '';
                    }
                }
            },
            { label: "售卖科室", name: "smksName", width: 80, align: "left" },
            { label: "售卖人员", name: "smryName", width: 80, align: "left" },
            {
                label: "记账日期", name: "jzrq", width: 100, align: "left",
                formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
            },
            { label: "退费人员", name: "tfryName", width: 80, align: "left" },
            {
                label: "退费日期", name: "RefundTime", width: 133, align: "left",
                formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' }
            }
            ],
            pager: "#gridPager",
            sortname: 'serialNumber ASC',
            viewrecords: true,
            gridComplete: function () {
                afterCompleteFunction();
            },
        });
        $("#btn_search").click(function () {
            if ($('#kssj').val() && $('#jssj').val() && ($('#kssj').val() > $('#jssj').val())) {
                $.modalAlert("开始记账日期不能大于结束记账日期", 'warning');
                return;
            }
            $gridList.jqGrid('setGridParam',
                {
                    postData: getSearchPostData(),
                    page: 1,
                    url: "/NonTreatmentItemManage/NonTreatmentItem/SelectNonTreatmentItemList"
                }).trigger('reloadGrid');
        });
    }

    //已退 背景色为红色
    function afterCompleteFunction() {
        var ids = $("#gridList").getDataIDs();
        for (i = 0; i < ids.length; i++) {
            var rowData = $("#gridList").getRowData(ids[i]);
            if (parseFloat(rowData.sl) < 0) {
                $("#" + ids[i]).find("td").addClass('danger');
            }
        }
    }

    //查询条件
    function getSearchPostData() {
        var sfdl = $("#sfdl").val();
        var keyword = $("#keyword").val();
        var smry = "";
        if ($("#smry").val()) {
            smry = $("#smry").attr('data-smryCode');
        }
        var smks = $("#smks").val();
        var kssj = $("#kssj").val();
        var jssj = $("#jssj").val();
        var kehu = $("#kehu").val();
        var zyh = $("#zyh").val();
        var blh = $("#blh").val();
        return { sfdl: sfdl, keyword: keyword, smry: smry, smks: smks, kssj: kssj, jssj: jssj, kehu: kehu, zyh: zyh, blh: blh };
    };

</script>

